package org.tau.workshop2011.parsing.AST

import org.tau.workshop2011.dynamic.RuntimeEnvironment
import org.tau.workshop2011.expressions.Type
import org.tau.workshop2011.semantics.DifferentTypesComparisionException

case class Comparision(left: DirectExpr, right: DirectExpr) extends DirectExpr {

  left.parent = this
  right.parent = this

  override def autoResolveType {
    super.resolveTypeTo(Type.tBoolean)
    (left.resultType, right.resultType) match {
      case (Type.tUnknown, Type.tUnknown) =>
      case (Type.tUnknown, t)             => resolveTypeTo (t)
      case (t, Type.tUnknown)             => resolveTypeTo (t)
      case (t1, t2)                       => if (t1 != t2) throw new DifferentTypesComparisionException(left, right)
    }
  }

  override def accept(visitor: ASTVisitor): Any = visitor.visit(this)

  override def toString = {
    left + "==" + right
  }
}
